<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
	</body>
	<script src="../js/jquery.min.js"></script>
	<script>
		/*async function timeout(ms) {
		  await new Promise((resolve) => {
		    setTimeout(resolve, ms);
		  });
		}
		let urls = ['../data/data.json',
					'../data/data1.json',
					'../data/data2.json']
		async function asyncPrint(urls, ms) {
		  await timeout(ms);
		  const response = await $.ajax({type:"get",url:urls,async:true});
		  console.log(urls);
		  return response;
		}
		async function getData(urls){
			let arr = [];
			arr[0] = await asyncPrint(urls[0], 50);
			arr[1] = await asyncPrint(urls[1], 100);
			arr[2] = await asyncPrint(urls[2], 10);
			arr[3] = await asyncPrint(urls[0], 0);
			for(let p of arr){
				console.log(p);
			}
		}
		getData(urls);
		console.log(setTimeout(function(){
			$.ajax({type:"get",url:urls[0],async:true})
			console.log('last5000');
		},5000));
		console.log(setTimeout(function(){
			$.ajax({type:"get",url:urls[0],async:true})
			console.log('last11');
		},11));
		console.log(setTimeout(function(){
			$.ajax({type:"get",url:urls[0],async:true})
			console.log('last10');
		},10));
		console.log(setTimeout(function(){
			$.ajax({type:"get",url:urls[0],async:true})
			console.log('last0');
		},0));*/
		
		//async 函数返回的是promise对象，可以用then方法对其进行进一步的操作
		//await 后面可以是promise对象和原始类型的值(Number、String、Boolean...)
		//基本用法：
		//async函数返回一个Promise对象，用then方法添加回调函数，当函数执行的时候，一旦遇到await就会先返回
		//等到异步操作完成，再接着执行函数体内后面的语句
		
	async function timeout(ms) {
		    await new Promise(function(resolve){
		    	return setTimeout(function(){
		    		resolve('122');
		    	},ms);
		    })
		}
		
		async function asyncPrint(ms) {
			console.log(timeout(ms));
		  const value = await timeout(ms);
		  console.log(value);
		}
		
		asyncPrint(50);
	</script>
</html>
